package com.jay.media.music.ui.sample

import android.os.Bundle
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import com.jay.media.music.core.audio.AudioRecorderUtils
import com.jay.media.music.core.audio.MediaRecordUtils
import com.jay.media.music.ui.R
import java.io.File

class AudioActivity : AppCompatActivity(), View.OnClickListener {
    val mediaRecordUtils = MediaRecordUtils()
    val audioRecorderUtils = AudioRecorderUtils()
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_audio)

        findViewById<View>(R.id.mediaRecordButton).setOnClickListener(this)
        findViewById<View>(R.id.stopMediaRecordButton).setOnClickListener(this)

        findViewById<View>(R.id.audioRecordButton).setOnClickListener(this)
        findViewById<View>(R.id.stopAudioRecordButton).setOnClickListener(this)
    }

    override fun onClick(v: View?) {
        when (v?.id) {
            R.id.mediaRecordButton -> {
                mediaRecordUtils.startRecord(
                    this, File(getExternalFilesDir("media"), "media.aac").absolutePath
                )
            }
            R.id.stopMediaRecordButton -> {
                mediaRecordUtils.stopRecord()
            }
            R.id.audioRecordButton -> {
                audioRecorderUtils.startRecord(
                    File(
                        getExternalFilesDir("media"),
                        "audio.aac"
                    ).absolutePath
                )
            }
            R.id.stopAudioRecordButton -> {
                audioRecorderUtils.stopRecord()
            }
            else -> {
            }
        }
    }
}